import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# 打开浏览器
service = Service(r'D:\Python3.14\chromedriver.exe')
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象
# 输入访问网址
driver.get("http://121.43.169.97:8848/pageA.html")

# 放大浏览器
driver.maximize_window()
# 放大暂停3秒后，设置窗口尺寸800*600像素
# time.sleep(3)
# driver.set_window_size(800, 600)
# 再暂停3秒后，将窗口移动屏幕坐标（0，500）
# time.sleep(3)
# driver.set_window_position(0, 500)

# 输入用户名信息，保持3秒后清除
# driver.find_element(By.ID, "userA").send_keys("admin")
# time.sleep(3)
# driver.find_element(By.ID, "userA").clear()
# # 刷新浏览器
# # driver.refresh()
#
# # 获取标题
# print(driver.title)
# # 获取网页地址
# print(driver.current_url)
# # 浏览器前进与后退，先打开百度再回到注册页面，后回到百度
# driver.find_element(By.XPATH, "//*[text()='打开百度']").click()
# time.sleep(2)
# driver.back()
# time.sleep(3)
# driver.forward()


"""
需求：打开注册A页面，完成以下操作
python基础).通过脚本执行输入用户名：admin；密码：123456；电话号码：18611111111；电子邮件：123@qq.com
2).间隔3秒，修改电话号码为：18600000000
3).间隔3秒，点击‘注册’按钮
4).间隔3秒，关闭浏览器
5).元素定位方法不限
"""
# python基础
driver.find_element(By.ID, "userA").send_keys("admin")
driver.find_element(By.XPATH, "//*[@id='passwordA']").send_keys("123456")
driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("18611111111")
driver.find_element(By.CSS_SELECTOR, ".emailA.dzyxA").send_keys("123@qq.com")
# 2
time.sleep(3)
driver.find_element(By.CSS_SELECTOR, "#telA").clear()
time.sleep(1)
driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("18600000000")
# 3
time.sleep(3)
driver.find_element(by=By.CSS_SELECTOR, value="p>button").click()
# 4
time.sleep(3)
driver.quit()


